package com.wmlive.hhvideo.service.presenter;

import android.text.TextUtils;

import com.wmlive.hhvideo.common.base.BasePresenter;
import com.wmlive.hhvideo.common.network.HttpConstant;
import com.wmlive.hhvideo.heihei.beans.main.UserBehavior;
import com.wmlive.hhvideo.heihei.beans.splash.InitCatchData;
import com.wmlive.hhvideo.service.view.UserBehaviorView;
import com.wmlive.networklib.entity.BaseResponse;
import com.wmlive.networklib.entity.DCNetObserver;

/**
 * 上传用户行为presenter
 * Created by vhawk on 2017/6/20.
 */

public class UserBehaviorPresenter extends BasePresenter<UserBehaviorView> {
    public UserBehaviorPresenter(UserBehaviorView view) {
        super(view);
    }

    /**
     * 上送用户观看视频，下载，分享灯行为
     * @param userBehavior
     */
    public void sendUserBehavior(UserBehavior userBehavior) {

        String url = InitCatchData.opusLogs();

        if (!TextUtils.isEmpty(url)) {
            executeRequest(HttpConstant.TYPE_USER_BEHAVIOR,
                    getHttpApi().sendUserBehavior(url,
                            userBehavior.getVideoId(),
                            userBehavior.getWtachlLength(),
                            userBehavior.getShareCount(),
                            userBehavior.getDownloadCount())
            ).subscribe(new DCNetObserver<BaseResponse>() {
                @Override
                public void onRequestDataReady(int requestCode, String message, BaseResponse response) {
                    if (viewCallback != null) {
                        viewCallback.handleUserBehaviorSucceed();
                    }
                }

                @Override
                public void onRequestDataError(int requestCode, int serverCode, String message) {
                    if (viewCallback != null) {
                        viewCallback.handleUserBehaviorFailure(message);
                    }
                }
            });

        }else {
            if (viewCallback != null) {
                viewCallback.handleNetError();
            }
        }
    }
}
